package org.dylan.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.NumericField;
import org.hibernate.search.annotations.Store;
import org.wltea.analyzer.lucene.IKAnalyzer;

@Entity
@Indexed
@Analyzer(impl = IKAnalyzer.class)
public class Book {
	@Id
	@GeneratedValue
	private Integer id;
	@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
	private String title;
	@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
	private String subTitle;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "catagory_id")
	@IndexedEmbedded
	private BookCatagory catagory;

	@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
	private String describe;
	// 出版社
	@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
	private String publisher;
	// 价格
	@Field(index = Index.YES, analyze = Analyze.NO, store = Store.YES)
	@NumericField(precisionStep=2)
	private Double price;

	private Date publicationDate;
	@IndexedEmbedded
	@ManyToMany
	@JoinTable(name = "book_author", joinColumns = { @JoinColumn(name = "book_id") }, inverseJoinColumns = { @JoinColumn(name = "author_id") })
	private Set<Author> authors;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSubTitle() {
		return subTitle;
	}

	public void setSubTitle(String subTitle) {
		this.subTitle = subTitle;
	}

	public Set<Author> getAuthors() {
		return authors;
	}

	public void setAuthors(Set<Author> authors) {
		this.authors = authors;
	}

	public BookCatagory getCatagory() {
		return catagory;
	}

	public void setCatagory(BookCatagory catagory) {
		this.catagory = catagory;
	}

	public Date getPublicationDate() {
		return publicationDate;
	}

	public void setPublicationDate(Date publicationDate) {
		this.publicationDate = publicationDate;
	}

	public String getDescribe() {
		return describe;
	}

	public void setDescribe(String describe) {
		this.describe = describe;
	}

	public String getPublisher() {
		return publisher;
	}

	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

}
